#include<stdio.h>
int n, a[10005],j=1;
void go(void);
int main() {
	int c;
	scanf_s("%d", &c);
	for (; c > 0; c--) {
		scanf_s("%d", &n);
		j = 1;
		for (int i = 1; i <= n;i++) {
			a[i] = 1;
		}
		for (int i = 1; i < n;i++) {
			go();
		}
		for (int i = 1; i <= n; i++) {
			if (a[i]) {
				printf("%d\n", i);
				break;
			}
		}
	}
	return 0;
}
void go(void) {
	int k = 0;
		while (k < 3) {
			if (a[j]) {
				k++;
				if (k == 3)
					a[j] = 0;
			}
			j++;
			if (j == n+1)
				j = 1;
	}
}